package com.apabi.service.impl;

import com.apabi.common.config.DataSource;
import com.apabi.common.config.DataSourceContextHolder;
import com.apabi.common.config.DynamicDataSource;
import com.apabi.common.enums.DocType;
import com.apabi.mapper.ApiMetaMapper;
import com.apabi.service.ApiMateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by huhu on 2018/1/17.
 */
@Service
public class ApiMateServiceImpl implements ApiMateService {

    @Autowired
    private ApiMetaMapper apiMetaMapper;

    @Override
    @DataSource(name=DataSource.sqlServerMetadataSource)
    public Map<String,String> selectDoc(String docId) {
        Map<String,String> map = null;
        String type = docId.substring(0,2);
        if(type.equals(DocType.BOOK.getValue())){
            map = apiMetaMapper.selectBook(docId);
        }else if(type.equals(DocType.JOURNAL.getValue())){
            map = apiMetaMapper.selectJournal(docId);
        }else if(type.equals(DocType.METTING.getValue())){
            map = apiMetaMapper.selectMeeting(docId);
        }else if(type.equals(DocType.NEWSPAPER.getValue())){
            map = apiMetaMapper.selectNewspaper(docId);
        }else if(type.equals(DocType.PATEND.getValue())){
            map = apiMetaMapper.selectPatent(docId);
        }else if(type.equals(DocType.STANDARD.getValue())){
            map = apiMetaMapper.selectStandard(docId);
        }else if(type.equals(DocType.THESIS.getValue())){
            map = apiMetaMapper.selectThesis(docId);
        }
        return map;
    }
}
